isLogin = (req) ->
	if req.session.user?
		true
	else
		false

checkLogin = (req,res,next) ->
	if !isLogin(req)
		res.redirect '/'
	else
		next()

notLogin = (req,res,next) ->
	if isLogin(req)
		if req.session.type is 't'
			res.redirect '/teacher'
		else if req.session.type is 's'
			res.redirect '/student'
		else
			res.redirect '/logout'
	else
		next()

module.exports = {
	checkLogin:checkLogin,
	notLogin:notLogin
}

